package net.wantong.tech.xa.run;

import lombok.extern.slf4j.Slf4j;
import net.wantong.tech.xa.service.DeleteHisDataService;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.LocalDate;
import org.joda.time.format.ISODateTimeFormat;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Scanner;

/**
 * 启动类
 *
 * @author MaShibo
 * 日期 :  2019/9/4
 */
@Slf4j
public class BootStrap {


    public static void main(String[] args) {
        if (args == null || args.length < 2) {
            log.info("请输入有效的参数");
            System.exit(0);
            return;
        }

        String startDate = args[0];
        LocalDate startLocalDate;
        try {
            startLocalDate = LocalDate.parse(startDate, ISODateTimeFormat.basicDate());
        } catch (Exception e) {
            log.error("起始日期解失败，格式：yyyyMMdd", e.getMessage());
            System.exit(-1);
            return;
        }

        String endDate = args[1];
        LocalDate endLocalDate;
        try {
            endLocalDate = LocalDate.parse(endDate, ISODateTimeFormat.basicDate());
        } catch (Exception e) {
            log.error("结束日期解析失败，格式：yyyyMMdd", e.getMessage());
            System.exit(-1);
            return;
        }

        log.info("请输入【Y】-确认是否开始删除【{}】-【{}】的消费流水数据", startDate, endDate);
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        while (!"Y".equalsIgnoreCase(StringUtils.trim(line))) {
            log.info("请输入【Y】-确认是否开始删除【{}】-【{}】的消费流水数据", startDate, endDate);
            line = scanner.nextLine();
        }

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        context.start();
        DeleteHisDataService service = context.getBean(DeleteHisDataService.class);
        service.execute(startLocalDate, endLocalDate);
        System.exit(0);
    }


}
